<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>TEACHER GRADE UPDATE</title>
</head>

<body>
	<?php
			$username = $_COOKIE['studialusername'];
			$password = $_COOKIE['studialuserpwd'];
			$userid = $_COOKIE['studialuserid'];
			$EventID = $_POST['EventID'];
			
			@ $db = mysql_pconnect("localhost","root","");
			
			if(!$db)
			{
				echo "<h2>Database does not exist!</h2>";
				exit;
			}
			
			$selectEvent = "SELECT * FROM `assignments` WHERE id = '".$EventID."'";
			$resultEvent = mysql_query($selectEvent);
			$rowEvent = mysql_fetch_array($resultEvent);
			
			$selectAssignmentSubmission = "SELECT * FROM `assignment_submission` a INNER JOIN `users` u ON a.user_id = u.id WHERE assignment_id = '".$EventID."'";
			$resultAssignmentSubmission = mysql_query($selectAssignmentSubmission);
			$rowAssignmentSubmission = mysql_fetch_array($resultAssignmentSubmission);
			$numAssignmentSubmission = mysql_num_rows($rowAssignmentSubmission);
			
			for($i=1; $i<=$numAssignmentSubmission; $i++)
			{
				$grade = $_POST[stripslashes($rowAssignmentSubmission['user_id'])];
				$query = "UPDATE `studial`.`assignment_submission` SET  `grade` = '".$grade."' WHERE user_id = '".$userid."' AND assignment_id = '".$EventID."'";
				mysql_query($query);
			}
		?>
</body>
</html>